package model;

import bean.Question;
import connection.DbConnection;
import java.sql.*;

import org.json.simple.*;
import java.net.*;
import java.util.*;

public class TimerImple{
	Question question;
	int CurrentTimer;
	
	/**
	 * 
	 * @param questionID
	 * @return an int array containing [timervalue, status]
	 */
	public int[] getCurrentTimer(int questionID){
		int[] ret = {-1, -1};
		try {
			DbConnection conn = new DbConnection();
			System.out.println("here! getTimer");
			String sql = "SELECT status, currentTimer FROM Question WHERE QuestionID="+questionID;
			PreparedStatement ps;
			ps = conn.getConn().prepareStatement(sql);
			System.out.println("SQL:"+sql);
			
			int timer = -1;
			int status = -1;
			System.out.println("here! getTimer2");
			ResultSet rs = ps.executeQuery();
			if(rs.next()){
				System.out.println("here! getTimer3");
				System.out.flush();
				status = rs.getInt(1);
				timer = rs.getInt(2);
			}
			ret[0] = timer;
			ret[1] = status;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return ret;
	}
}